//
//  LCWMiddleView.swift
//  MyWB
//
//  Created by 李成万 on 16/6/29.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit
import SnapKit

class LCWMiddleView: UIView {

    var selfBottomConstraint : Constraint?
    
    var status:LCWStatus?{
        didSet{
            retweetedLabel.attributedText = status?.retweeted_status?.attrString
            
            //卸载
            selfBottomConstraint?.uninstall()
            if status?.retweeted_status?.pic_urls?.count == 0{
                picView.hidden = true
                self.snp_makeConstraints { (make) -> Void in
                    selfBottomConstraint = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(Padding).constraint
                }
            }else{
                picView.pic_urls = status?.retweeted_status?.pic_urls
                picView.hidden = false
                self.snp_makeConstraints { (make) -> Void in
                    selfBottomConstraint = make.bottom.equalTo(picView.snp_bottom).offset(Padding).constraint
                }
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private lazy var retweetedLabel : UILabel = UILabel(messageColor: UIColor.blackColor(), textFont: 15, maxWidth: SCREENW - 2*Padding)
    
    private lazy var picView : LCWPicCollection = LCWPicCollection()
    func setupUI(){
        backgroundColor = RGB(237, green: 237, blue: 237)
        addSubview(retweetedLabel)
        addSubview(picView)
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(Padding)
            make.top.equalTo(self).offset(Padding)
        }
        
        picView.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self).offset(Padding)
            make.top.equalTo(retweetedLabel.snp_bottom).offset(Padding)
        }
        self.snp_makeConstraints { (make) -> Void in
           selfBottomConstraint = make.bottom.equalTo(retweetedLabel.snp_bottom).offset(Padding).constraint
        }
    }
}
